const proxy = require('http-proxy-middleware');

// 导入compression-webpack-plugin
const CompressionWebpackPlugin = require('compression-webpack-plugin');
// 定义压缩文件类型
const productionGzipExtensions = ['js', 'css'];

module.exports = {
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            // 为生产环境修改配置...
            config.plugins.push(
                new CompressionWebpackPlugin({
                    filename: '[path].gz[query]',
                    algorithm: 'gzip',
                    test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
                    threshold: 10240,
                    minRatio: 0.8
                })
            );
        } else {
            config.plugins.push(
                new CompressionWebpackPlugin({
                    filename: '[path].gz[query]',
                    algorithm: 'gzip',
                    test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
                    threshold: 10240,
                    minRatio: 0.8
                })
            );
        }
    },
    publicPath: './',
    assetsDir: 'static',
    productionSourceMap: false,
    devServer: {
        host: 'localhost',
        port: 9092,
        https: false,
        hotOnly: false,
        open: true, //配置自动启动浏览器 那你                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                2 
        proxy: {
            '/usercenter': {
                target: 'http://localhost:9091',
                //target: 'https://v.canas.cn',
                changeOrigin: true
            },
            '/manager': {
                target: 'http://localhost:9091',
                //target: 'https://v.canas.cn',
                changeOrigin: true
            }
        }
    }
}